package Member1;

import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JLabel;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Color;

public class Delete extends JPanel {
	
	private static final String String = null;

	Data6[] d;
	int i;
	
	private JTextField textField;
	private JButton btnNewButton;
	private JLabel lblNewLabel;
	private JTextField textField_1;
	private JTextField textField_2;
	private JTextField textField_3;
	private JTextField textField_4;
	private JTextField textField_5;
	private JButton button;
	private JLabel label;
	private JLabel label_1;
	private JLabel label_2;
	private JLabel lblE;
	private JLabel label_4;

	/**
	 * Create the panel.
	 */
	public void setD(Data6[] d) {
		this.d = d;
	}
	
	public Delete() {
		setBackground(Color.LIGHT_GRAY);
		setLayout(null);
		add(getTextField());
		add(getBtnNewButton());
		add(getLblNewLabel());
		add(getTextField_1());
		add(getTextField_2());
		add(getTextField_3());
		add(getTextField_4());
		add(getTextField_5());
		add(getButton());
		add(getLabel());
		add(getLabel_1());
		add(getLabel_2());
		add(getLblE());
		add(getLabel_4());
	}
	
	private JTextField getTextField() {
		if (textField == null) {
			textField = new JTextField();
			textField.setBounds(105, 10, 116, 21);
			textField.setColumns(10);
		}
		return textField;
	}
	private JButton getBtnNewButton() {
		if (btnNewButton == null) {
			btnNewButton = new JButton("검색");
			btnNewButton.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
				if(textField.getText().equals(""))
					JOptionPane.showMessageDialog(null,"빈공간입니다.");
				if(d[i].name!=textField.getText()){
					JOptionPane.showMessageDialog(null,"검색된 데이터가 없습니다.");
				}
					for(i=0; i<d.length; i++){
						if(d[i]==null){
							continue;
						}
						if(d[i].name.equals(textField.getText())){
							textField_1.setText(d[i].name);
							textField_2.setText(d[i].address);
							textField_3.setText(d[i].phone);
							textField_4.setText(d[i].email);
							textField_5.setText(d[i].age+" ");
							
							break;
						}
					}
					System.out.println(i);
					
				}
			});
			btnNewButton.setBounds(262, 9, 97, 23);
		}
		return btnNewButton;
	}
	private JLabel getLblNewLabel() {
		if (lblNewLabel == null) {
			lblNewLabel = new JLabel();
			lblNewLabel.setText("이름 :");
			lblNewLabel.setBounds(37, 13, 57, 15);
		}
		return lblNewLabel;
	}
	private JTextField getTextField_1() {
		if (textField_1 == null) {
			textField_1 = new JTextField();
			textField_1.setBounds(105, 80, 116, 21);
			textField_1.setColumns(10);
		}
		return textField_1;
	}
	private JTextField getTextField_2() {
		if (textField_2 == null) {
			textField_2 = new JTextField();
			textField_2.setColumns(10);
			textField_2.setBounds(105, 111, 116, 21);
		}
		return textField_2;
	}
	private JTextField getTextField_3() {
		if (textField_3 == null) {
			textField_3 = new JTextField();
			textField_3.setColumns(10);
			textField_3.setBounds(105, 142, 116, 21);
		}
		return textField_3;
	}
	private JTextField getTextField_4() {
		if (textField_4 == null) {
			textField_4 = new JTextField();
			textField_4.setColumns(10);
			textField_4.setBounds(105, 173, 116, 21);
		}
		return textField_4;
	}
	private JTextField getTextField_5() {
		if (textField_5 == null) {
			textField_5 = new JTextField();
			textField_5.setColumns(10);
			textField_5.setBounds(105, 204, 116, 21);
		}
		return textField_5;
	}
	private JButton getButton() {
		if (button == null) {
			button = new JButton("삭제");
			button.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					
					boolean flag = true;
					if(textField_1.getText().equals("")){
						JOptionPane.showMessageDialog(null,"검색하지 않았습니다.");
					}
					if (textField_1.getText().equals(""))
						flag = false;
					else if (textField_2.getText().equals(""))
						flag = false;
					else if (textField_3.getText().equals(""))
						flag = false;
					else if (textField_4.getText().equals(""))
						flag = false;
					else if (textField_5.getText().equals(""))
						flag = false;
					if (flag) {
						Data6 data = new Data6();
						textField_1.setText("");
						textField_2.setText(null);
						textField_3.setText(null);
						textField_4.setText(null);
						textField_5.setText(null);
		
								d[i] = data;
						}
					Data6 data = new Data6();
					d[i] = data;
					for(int j=i;j<d.length-1;j++){
						if(d[i]==null) continue;
						d[j]=d[j+1];
				
					}
					
				}
			});
			button.setBounds(262, 141, 97, 23);
		}
		return button;
	}
	private JLabel getLabel() {
		if (label == null) {
			label = new JLabel();
			label.setText("이름 :");
			label.setBounds(37, 83, 57, 15);
		}
		return label;
	}
	private JLabel getLabel_1() {
		if (label_1 == null) {
			label_1 = new JLabel();
			label_1.setText("주소 :");
			label_1.setBounds(37, 114, 57, 15);
		}
		return label_1;
	}
	private JLabel getLabel_2() {
		if (label_2 == null) {
			label_2 = new JLabel();
			label_2.setText("전화번호 :");
			label_2.setBounds(37, 145, 57, 15);
		}
		return label_2;
	}
	private JLabel getLblE() {
		if (lblE == null) {
			lblE = new JLabel();
			lblE.setText("E메일 :");
			lblE.setBounds(37, 176, 57, 15);
		}
		return lblE;
	}
	private JLabel getLabel_4() {
		if (label_4 == null) {
			label_4 = new JLabel();
			label_4.setText("나이 :");
			label_4.setBounds(37, 207, 57, 15);
		}
		return label_4;
	}
}
